import Vue from 'vue'
import Router from 'vue-router'
import err from '@/views/error/404.vue'
import login from '@/views/login/index.vue'
import pwdReset from '@/views/login/pwdReset.vue'
import register from '@/views/register/index.vue'
import editbox from '@/views/editbox/index.vue'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
let defaultRouter = [
  {
    path: '/',
    redirect: '/login',
    component: () => import('@/views/Main.vue'),
    children: [
      {
        path: '/login',
        component: login,
        meta: {
          title: '用户登录',
          id: '用户登录'
        }
      },
      {
        path: '/register',
        component: register,
        meta: {
          title: '用户注册',
          id: '用户注册'
        }
      },
      {
        path: '/pwdReset',
        component: pwdReset,
        meta: {
          title: '密码重置',
          id: '密码重置'
        }
      }
    ]
  },
  {
    path: '/editbox',
    component: editbox,
    meta: {
      title: '代码编辑',
      id: '代码编辑'
    },
    name: 'editbox'
  },
  {
    path: '/404',
    component: err
  },
  {
    path: '/userAuth',
    component: () => import('@/views/Center.vue'),
    redirect: '/userAuth',
    children: [
      {
        path: '/userAuth',
        component: () => import('@/views/userAuth/index.vue'),
        meta: {
          title: '实名认证',
          id: '实名认证',
          requiresAuth: false
        },
        name: 'userAuth'
      }
    ]
  }
]
export default new Router({
  routes: defaultRouter
})
Router.selfaddRoutes = function (params) {
  Router.matcher = new Router().matcher
  Router.addRoutes(params)
}